﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.Utilities;
using FrameworkManapro.WebUI;


namespace GMAC.ReportingSystem.Business.Components
{
    public class DealerGroupComponent : IBusinessComponent<Entities.DealerGroup>
    {
        private DataAccess.DealerGroupDataAccess dac;

        public DealerGroupComponent()
        {
            dac = new DataAccess.DealerGroupDataAccess();
        }

        #region IBusinessComponent<DealerGroup> Members

        public int Create(Entities.DealerGroup entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }

        public int Delete(Entities.DealerGroup entityToDelete)
        {
            if (entityToDelete.ID <= 0)
                throw new ArgumentOutOfRangeException("ID", "Value must be greater than zero.");

            return dac.Delete(entityToDelete);
        }

        public int Edit(Entities.DealerGroup entityToEdit)
        {
            if (entityToEdit.ID <= 0)
                throw new ArgumentOutOfRangeException("ID", "Value must be greater than zero.");

            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        public Entities.DealerGroup GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        protected bool Validate(Entities.DealerGroup DealerGroup)
        {
            if (DealerGroup == null) throw new ArgumentNullException("DealerGroup", "The argument cannot be null.");
            if (string.IsNullOrEmpty(DealerGroup.Name.ToString())) throw new ArgumentNullException("Name", "The argument cannot be null.");
            if (string.IsNullOrEmpty(DealerGroup.Status.ToString())) throw new ArgumentNullException("Status", "The argument cannot be null.");
            return true;
        }

        #endregion


        public Entities.DealerGroupCollection GetList()
        {
            return dac.GetList();
        }

        public Entities.DealerGroupCollection Search(string Name, PagingDetails paging)
        {
            return dac.Search(Name, paging);
        }

    }
}
